package com.example.yichuangyun.mvvm.ui.fragment;

import android.os.Bundle;

import androidx.lifecycle.Observer;

import com.example.yichuangyun.R;
import com.example.yichuangyun.config.Constant;
import com.example.yichuangyun.databinding.FragmentBusinessRecordBinding;
import com.example.yichuangyun.model.order.ServiceRecordModel;
import com.example.yichuangyun.mvvm.base.BaseFragment;
import com.example.yichuangyun.mvvm.ui.activity.order.view.OrderDetailsViewModel;
import com.example.yichuangyun.mvvm.ui.adapter.OrderServiceAdapter;

import java.util.List;

/**
 * 订单详情-服务
 */
public class OrderServiceFragment extends BaseFragment<FragmentBusinessRecordBinding, OrderDetailsViewModel> {

    private OrderServiceAdapter adapter;

    @Override
    protected OrderDetailsViewModel bindModel() {
        return getViewModel(this, OrderDetailsViewModel.class);
    }

    @Override
    protected void initInject() {
        getFragmentComponent().inject(this);
    }

    @Override
    public void initData() {
        adapter = new OrderServiceAdapter(mContext);
        binding.recyclerView.setAdapter(adapter);
        adapter.setEmptyViewEnable(true);
        adapter.setEmptyViewLayout(mContext, R.layout.layout_empty_list2);
        Bundle bundle = getArguments();
        if (bundle != null) {
            String id = bundle.getString(Constant.idKey);
            viewModel.getOrderDetailsForService(id);
        }
    }

    @Override
    protected void initClick() {
        viewModel.serviceListMutableLiveData.observe(this, serviceModels -> adapter.submitList(serviceModels));
    }

    public static OrderServiceFragment newInstance(String id) {
        Bundle bundle = new Bundle();
        bundle.putString(Constant.idKey, id);
        OrderServiceFragment fragment = new OrderServiceFragment();
        fragment.setArguments(bundle);
        return fragment;
    }
}
